package com.flying.scorer.score.equity.quarterlyreport;


import com.flying.refdata.model.Quarter;
import com.flying.refdata.model.equity.EquityInfo;
import com.flying.refdata.model.equity.QuarterlyReport;
import com.flying.refdata.service.ReportService;
import com.flying.scorer.score.ScoreException;
import com.flying.scorer.score.equity.AbstractEquityScorer;
import com.flying.utils.bean.BeanUtil;

public abstract class AbstractQuarterlyReportScorer extends AbstractEquityScorer {

    private ReportService reportService;

    public AbstractQuarterlyReportScorer(ReportService reportService) {
        this.reportService = reportService;
    }

    QuarterlyReport getQuarterlyReport(EquityInfo info, int date) throws ScoreException {
        QuarterlyReport qr = reportService.getLatestQuarterlyReport(info, date);
        if (qr == null)
            throw new ScoreException("Can't find the quarterly report. date:" + date + "equity info:" + BeanUtil.describe(info));
        return qr;
    }

    QuarterlyReport getPreviousQuarterlyReport(EquityInfo info, int year, Quarter quarter) throws ScoreException {
        QuarterlyReport qr = reportService.getQuarterlyReport(info, year, quarter);
        if (qr == null)
            throw new ScoreException("Can't find the quarterly report. year:" + year
                    + "quarter:" + quarter.toString()
                    + "equity info:" + BeanUtil.describe(info));
        return qr;
    }
}
